package zd.cornermemory.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import zd.cornermemory.R;

public class ScrambleAdapter extends BaseAdapter {
	private Context mContext;
	private List<String> mListData;
	private LayoutInflater mInflater;

	final class ViewHolder {
		public TextView textView;
		public ImageView check;
	}

	public ScrambleAdapter(Context context, List<String> mListData) {
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
		this.mListData = mListData;
	}
	
	public void setData(List<String> data) {
		this.mListData = data;
	}
	


	@Override
	public int getCount() {
		if(mListData != null) return mListData.size();
		return 0;
	}

	@Override
	public Object getItem(int arg0) {
		if(mListData != null) return mListData.get(arg0);
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			int resId = R.layout.scramble_item;
			convertView = mInflater.inflate(resId, null);
			holder.textView = (TextView) convertView.findViewById(R.id.text1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if(mListData != null) {
			holder.textView.setText((position+1)+". "+(mListData.get(position)));
			if (mListData.size() == 1) {//单条打乱不显示序号
				holder.textView.setText(mListData.get(position));
			}

		}
		return convertView;
	}
}
